package com.zetyun.tiger.format.upper;

import com.zetyun.rt.meta.annotation.ActionMeta;
import com.zetyun.rt.sdk.action.MapAction;
import com.zetyun.rt.sdk.model.RtEvent;

import java.util.Map;

@ActionMeta(
        id = "tiger.to-upper-case",
        tags = {"操作算子"},
        category = "conversion",
        name = "ToUpperCase",
        description = "除op_字段外，其他所有字段全部转为大写字段",
        status = ActionMeta.Status.PUBLIC
)
public class ToUpperCaseAction extends MapAction {
    @Override
    public RtEvent apply(RtEvent in) throws Exception {
        RtEvent rtEvent = new RtEvent();

        Map<String, Object> fields = in.getFields();
        rtEvent.putHeaders(in.getHeaders());

        rtEvent.setValue("op_", fields.get("op_"));
        for (Map.Entry<String, Object> entry : fields.entrySet()) {
            String key = entry.getKey();
            if (key.equals("op_")) {
                continue;
            }
            rtEvent.setValue(key.toUpperCase(), entry.getValue());
        }


        return rtEvent;
    }
}
